class Admin::User < ActiveRecord::Base
  #configure you user model
  rolify(strict: true)


  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  #谁属于我
  has_many :posts, inverse_of: :admin_user

  has_many :blog_sorts, inverse_of: :admin_user
  #由于使用了双向关联，并且另一方的关联名为admin_user,外键则默认变为admin_user_id
  has_many :themes, inverse_of: :admin_user

  #默认情况下外键名为user_id
  #由于使用了多对多关联，此处不需要设置直接的外键
  #has_many :permissions, foreign_key: :admin_user_id

  has_and_belongs_to_many :permissions,
                          ->{uniq},
                          join_table: :admin_users_permissions


  def empty?(value= '')
    if self.email==value && self.encrypted_password== value && self.id.nil?
      true
    else
      false
    end
  end
end
